package UCM;

import Source.DeleteUser;
import Views.ViewDeleteUser;

/**
 * The use case for delete user
 * @author Joshua King
 */
public class UCDeleteUser implements UCController {

    private ViewDeleteUser view;
    private DeleteUser model = new DeleteUser();

    /**
     * Initualises the view
     * @param view
     */
    public UCDeleteUser(ViewDeleteUser view) {
        this.view = view;
        view.loadTo(model);
    }

    /**
     * Precondition: User is on delete user view.

    1. User enters their password and click delete account.
    2. System gets data entered by user.
    3. System authenticates the password.
    4. System asks again if the wish to delete the account.
    5. System deletes user.
    6. System logs the user out.
    7. System updates UI to show success.
     
    Postcondition: User is on main UI, and the account has been deleted.

    Unsuccessful Outcomes:

    3a) Password is entered incorrectly.
    System displays delete account UI and informs user that password was entered incorrectly.
    5a) System can't delete data.
    System updates the UI informing the user that the service is currently unavailable.
    5b) System receives notice that an error has occurred.
    System updates the UI informing the user that there was an internal error.
     */
    public void run() {
        //2. System gets data entered by user.
        view.setModelData();
        //3. System authenticates the password.
        if (model.confirmPassword()) {
            //4. System asks again if the wish to delete the account.
            //confirmView.updateConfirm();
            /*
            if (model.deleteUser()) {
                view.updateSuccess();
            } else {
                view.updateFailure("The system failed to connect to delete account.");
            }*/
        } else {
            view.updateFailure("Password does not match the account.");
        }
    }
}
